package com.happy.cat.project.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.happy.cat.common.utils.SecurityUtils;
import com.happy.cat.common.utils.poi.ExcelUtil;
import com.happy.cat.framework.web.controller.BaseController;
import com.happy.cat.framework.web.domain.AjaxResult;
import com.happy.cat.framework.web.page.TableDataInfo;
import com.happy.cat.framework.aspectj.lang.annotation.Log;
import com.happy.cat.framework.aspectj.lang.enums.BusinessType;
import com.happy.cat.project.system.domain.CatUserNoble;
import com.happy.cat.project.system.service.ICatUserNobleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 贵族设定Controller
 *
 * @author verne
 * @date 2020-07-18
 */
@AllArgsConstructor
@RestController
@RequestMapping("/system/userNoble" )
@Api("贵族设定 API")
public class CatUserNobleController extends BaseController {

    private final ICatUserNobleService iCatUserNobleService;

    @GetMapping(value = "/all" )
    public AjaxResult all() {
        return AjaxResult.success(iCatUserNobleService.list());
    }
    /**
     * 查询贵族设定列表
     */
    @ApiOperation(value = "查询贵族设定列表",notes = "查询贵族设定列表",response = TableDataInfo.class)
    @PreAuthorize("@ss.hasPermi('system:userNoble:list')")
    @GetMapping("/list")
    public TableDataInfo list(CatUserNoble catUserNoble)
    {
        startPage();
        LambdaQueryWrapper<CatUserNoble> lqw = new LambdaQueryWrapper<CatUserNoble>();
        if (catUserNoble.getName() != null){
            lqw.like(CatUserNoble::getName ,catUserNoble.getName());
        }
        if (catUserNoble.getFirstMoney() != null){
            lqw.eq(CatUserNoble::getFirstMoney ,catUserNoble.getFirstMoney());
        }
        if (catUserNoble.getRenewMoney() != null){
            lqw.eq(CatUserNoble::getRenewMoney ,catUserNoble.getRenewMoney());
        }
        if (catUserNoble.getReturnMoney() != null){
            lqw.eq(CatUserNoble::getReturnMoney ,catUserNoble.getReturnMoney());
        }
        if (catUserNoble.getBroadcast() != null){
            lqw.eq(CatUserNoble::getBroadcast ,catUserNoble.getBroadcast());
        }
        if (catUserNoble.getEffects() != null){
            lqw.eq(CatUserNoble::getEffects ,catUserNoble.getEffects());
        }
        if (catUserNoble.getMedal() != null){
            lqw.eq(CatUserNoble::getMedal ,catUserNoble.getMedal());
        }
        if (catUserNoble.getSeat() != null){
            lqw.eq(CatUserNoble::getSeat ,catUserNoble.getSeat());
        }
        if (catUserNoble.getApproach() != null){
            lqw.eq(CatUserNoble::getApproach ,catUserNoble.getApproach());
        }
        if (catUserNoble.getCard() != null){
            lqw.eq(CatUserNoble::getCard ,catUserNoble.getCard());
        }
        if (catUserNoble.getAccelerate() != null){
            lqw.eq(CatUserNoble::getAccelerate ,catUserNoble.getAccelerate());
        }
        if (catUserNoble.getSpeaker() != null){
            lqw.eq(CatUserNoble::getSpeaker ,catUserNoble.getSpeaker());
        }
        if (catUserNoble.getBubble() != null){
            lqw.eq(CatUserNoble::getBubble ,catUserNoble.getBubble());
        }
        if (catUserNoble.getPrivacy() != null){
            lqw.eq(CatUserNoble::getPrivacy ,catUserNoble.getPrivacy());
        }
        if (catUserNoble.getCustomMade() != null){
            lqw.eq(CatUserNoble::getCustomMade ,catUserNoble.getCustomMade());
        }
        if (catUserNoble.getAnti() != null){
            lqw.eq(CatUserNoble::getAnti ,catUserNoble.getAnti());
        }
        if (catUserNoble.getHousekeeper() != null){
            lqw.eq(CatUserNoble::getHousekeeper ,catUserNoble.getHousekeeper());
        }
        if (catUserNoble.getStealth() != null){
            lqw.eq(CatUserNoble::getStealth ,catUserNoble.getStealth());
        }
        if (catUserNoble.getCreateDate() != null){
            lqw.eq(CatUserNoble::getCreateDate ,catUserNoble.getCreateDate());
        }
        if (catUserNoble.getStatus() != null){
            lqw.eq(CatUserNoble::getStatus ,catUserNoble.getStatus());
        }
        List<CatUserNoble> list = iCatUserNobleService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出贵族设定列表
     */
    @ApiOperation(value = "导出贵族设定列表",notes = "导出贵族设定列表",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userNoble:export')" )
    @Log(title = "贵族设定" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(CatUserNoble catUserNoble) {
        LambdaQueryWrapper<CatUserNoble> lqw = new LambdaQueryWrapper<CatUserNoble>(catUserNoble);
        List<CatUserNoble> list = iCatUserNobleService.list(lqw);
        ExcelUtil<CatUserNoble> util = new ExcelUtil<CatUserNoble>(CatUserNoble. class);
        return util.exportExcel(list, "userNoble" );
    }

    /**
     * 获取贵族设定详细信息
     */
    @ApiOperation(value = "获取贵族设定详细信息",notes = "获取贵族设定详细信息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userNoble:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {

        return AjaxResult.success(iCatUserNobleService.getById(id));
    }

    /**
     * 新增贵族设定
     */
    @ApiOperation(value = "新增贵族设定",notes = "新增贵族设定",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userNoble:add')" )
    @Log(title = "贵族设定" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CatUserNoble catUserNoble) {
        catUserNoble.setCreateDate(new Date());
        catUserNoble.setCreateBy(SecurityUtils.getUsername());
        return toAjax(iCatUserNobleService.save(catUserNoble) ? 1 : 0);
    }

    /**
     * 修改贵族设定
     */
    @ApiOperation(value = "修改贵族设定",notes = "修改贵族设定",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userNoble:edit')" )
    @Log(title = "贵族设定" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CatUserNoble catUserNoble) {
        catUserNoble.setCreateDate(new Date());
        catUserNoble.setCreateBy(SecurityUtils.getUsername());
        return toAjax(iCatUserNobleService.updateById(catUserNoble) ? 1 : 0);
    }

    /**
     * 删除贵族设定
     */
    @ApiOperation(value = "删除贵族设定",notes = "删除贵族设定",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userNoble:remove')" )
    @Log(title = "贵族设定" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iCatUserNobleService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
